<?php

namespace app\helper;

use app\atrait\Single;
use app\model\GameAccountBan;
use Exception;

class AccountBan
{

    use Single;


    /**
     * 账号封禁检查
     *
     * @param $game
     * @param $account
     * @return void
     * @throws Exception
     */
    public function Check($game, $account): void
    {

        $info = GameAccountBan::query()->where('game', $game)->where('type', 1)->where('account', $account)->first();

        if ($info) {
            if (strtotime($info->relieve_at) > time()) {
                throw new Exception('当前账号正在封禁中', 500);
            } else {
                $info->update([
                    'state' => 0,  // 解除封禁
                ]);
            }
        }

    }

}